package com.chencs.app.lianmeng.service;

import com.chencs.app.AppCommon;
import com.chencs.app.lianmeng.mapper.LMMemberMapper;
import com.chencs.app.lianmeng.mapper.LMProductMapper;
import com.chencs.biz.Common;
import com.chencs.vo.biz.lianmeng.*;
import com.chencs.vo.net.lmrequest.*;
import com.chencs.vo.net.lmresponse.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LMProductSer {

    @Autowired
    private LMProductMapper mapper;
    @Autowired
    private LMMemberMapper memberMapper;


    /**
     * 获取商品详情
     * @param request
     * @return
     */
    public LmProductResponse findProductByPid(LmProductRequest request){
        LmProductResponse response = new LmProductResponse();
        LmProduct product = mapper.findProductById(request.getId());
        if(product!=null){
            response.setProduct(product);
            response.setCode(AppCommon.SUCCESS);
            response.setMsg(AppCommon.SUCCESSMSG);
            //优惠券相关处理

        }else{
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }
        return  response;
    }

    /**
     * 获取商品列表
     * @param request
     * @request
     */
    public LmProductListResponse getProductList(LmProductListRequest  request){
        LmProductListResponse response = new LmProductListResponse();
        return  response;
    }


    /**
     *搜索商品列表
     * @param request
     * @request
     */
    public LmProductListResponse search(LmSearchRequest request){
        LmProductListResponse response = new LmProductListResponse();
        return  response;
    }


    /**
     * 获取分类
     * @param request
     * @return
     */
    public LmCategoryResponse getCategory(LmCategoryRequest request){
         LmCategoryResponse response = new LmCategoryResponse();
        List<LmCategory> categories = mapper.getCategory(request.getSex());
        response.setCategoryList(categories);
      return  response;
    }


    /**
     * 获取小分类
     * @param request
     * @return
     */
    public LmCategoryItemResponse  getCategoryItem(LmCategoryItemRequest request){
        LmCategoryItemResponse response = new LmCategoryItemResponse();
        List<LmCategory_item> items = mapper.getCategoryItem(request.getCid());
        List<LmCategory_Banner> banner = mapper.getCategoryBanner(request.getCid());
        response.setCategory_items(items);
        response.setBanners(banner);
        return  response;
    }


    /**
     * 获取优惠券
     * @param request
     * @return
     */
    public LmGetCouponsResponse getCoupons(LmProductRequest request){
        LmGetCouponsResponse response = new LmGetCouponsResponse();
        //获取用户的mm_id //生成优惠券

        String mm_id;
        LmAdPosition lmAdPosition = memberMapper.findPidByUid(request.getUid());
        if(lmAdPosition==null){ //如果该用户没有广告位
            mm_id = Common.DEF_PID;
        }else{
            mm_id = lmAdPosition.getPid();
        }




        return  response;

    }





}
